package com.blast.sspai.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import com.blast.sspai.R;
import com.blast.sspai.adapter.CommunityListAdapter;
import com.melnykov.fab.FloatingActionButton;

/**
 * 侧滑菜单中的社区页面
 */
public class CommunityFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener, AdapterView.OnItemClickListener {

    /**
     * 数据显示列表
     */
    private ListView mListView;
    /**
     * 右下角悬浮按钮
     */
    private FloatingActionButton mFab;
    /**
     * 下拉刷新
     */
    private SwipeRefreshLayout mSwipeRefreshLayout;
    /**
     * 适配器
     */
    private CommunityListAdapter mAdapter;

    public CommunityFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_community, container, false);

        //初始化控件
        initViews(view);

        //TODO  ....
        //mAdapter = new CommunityListAdapter(getActivity(), )

        //设置事件各种监听
        mSwipeRefreshLayout.setOnRefreshListener(this);
        mFab.attachToListView(mListView);
        mListView.setOnItemClickListener(this);

        return view;
    }

    private void initViews(View view) {
        mListView = (ListView) view.findViewById(R.id.listView);
        mFab = (FloatingActionButton) view.findViewById(R.id.fab);
        mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipeRefreshLayout);
    }

    /**
     * 下拉刷新回调
     */
    @Override
    public void onRefresh() {

    }

    /**
     * ListView点击事件回调
     *
     * @param parent
     * @param view
     * @param position
     * @param id
     */
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

    }
}
